
#include "ConfigClient.h"

namespace Config
{

	//ConfigClient ConfigClient::_instance;

	ConfigClient::ConfigClient()
	{
		
		//ic->load("config.client");
		try
		{
			Ice::InitializationData initData;
			initData.properties = Ice::createProperties();

			initData.properties->load("config.slave");
			ic = Ice::initialize(initData);
			//Ice::ObjectPrx base = ic->stringToProxy("ConfigMaster:tcp -h 127.0.0.1 -p 10000");
			master = ConfigMasterPrx::checkedCast(ic->propertyToProxy("ConfigMaster.Proxy")->ice_timeout(2000));
			//Ice::ObjectPrx base = ic->propertyToProxy("ConfigMaster.Proxy")->ice_timeout(2000);
			//master = ConfigMasterPrx::checkedCast(base);
			if(!master)
			{
				cerr << " [ConfigSlaveWork::run] invalid proxy [master]" << endl;
				exit(1);
			}
			//_seqObjectPrx.push_back(base);
			//Ice::ObjectPrx base1 = base->ice_connectionId("g1");
			//base1->ice_ping();
			//_seqObjectPrx.push_back(base1);
			//Ice::ObjectPrx base2 = base->ice_connectionId("g2");
			//base2->ice_ping();
			//_seqObjectPrx.push_back(base2);
		}
		catch (const Ice::Exception& ex)
		{
			cerr<<"catch exception "<<ex.what()<<endl;
		}
	}

	ConfigClient & ConfigClient::getObj()
	{
		static ConfigClient instance;
		return instance;
	}

	ConfigMasterPrx ConfigClient::getMasterPrx()
	{
		   Poco::FastMutex::ScopedLock lock(_m);
		   //ConfigMasterPrx master =  ConfigMasterPrx::checkedCast(_seqObjectPrx[i]);
		   //if(!master)
		   //{
			  // cerr << " [ConfigSlaveWork::run] invalid proxy [master]" << endl;
			  // exit(1);
		   //}
		return master;
	}



}

